package chen.web.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import chen.web.user.NoPermissionException;

@Component
public class ExceptionReslover implements HandlerExceptionResolver {

	@Override
	public ModelAndView resolveException(HttpServletRequest request,
			HttpServletResponse response, Object handler, Exception ex) {
		// TODO Auto-generated method stub
		ModelAndView mav = new ModelAndView();
		if(ex instanceof ResourceNotFoundException){
			response.setStatus(404);
			mav.setViewName("default/error/404");
		}else if(ex instanceof NoPermissionException){
			response.setStatus(403);
			mav.setViewName("default/error/403");
		} else {
			response.setStatus(500);
			mav.setViewName("default/error/error");
		}
		return mav;
	}

}
